require("find");

function hasBottomBar ()
  local result = false;
  
  local x1, y1 = findMultiColorInRegionFuzzy(0xd9c7c2,"-1|13|0xd9c7c2,-31|21|0x794d2f,-10|-39|0x7e2513", 95, 1905, 943, 2205, 1239);
  if x1 > -1 then
    tap(x1, y1);
    mSleep(500);
    printLog("第一个判断确定有底部栏");
    result = true;
  end
  
  if result == false then
    local x2, y2 = findMultiColorInRegionFuzzy(0xdecec8,"7|123|0xc1564d,-27|114|0x61141d,-27|-27|0xa68d8d,-27|9|0xa99192,-18|134|0x2b0912", 95, 2083, 935, 2199, 1240);
    if x2 > -1 then
      printLog("第二个判断确定有底部栏");
      
      result = true;
    end	
  end
  
  if result then
    --滑动到最右边
    swip(2172,515, 1404,526);
    swip(2172,515, 1404,526);
    mSleep(500);
  end
  
  return result;
  
end


--判断当前页面
function isPage (pageName) 
  --判断是否是庭院
  if pageName == "庭院" then
    printLog("判断是否为--庭院");
    
    if hasBottomBar() then
      
      local x, y = findMultiColorInRegionFuzzy(0x211842,"0|12|0x211842,-27|38|0x6f73b1,0|-26|0x7b7bbb,-20|-26|0x7776b8", 95, 1904, 564, 1980, 640)
      if x > -1 then
        
        printLog("该界面是庭院");
        return true;
      end
    end
    
    return false;
  end
  
  
  --判断是否是盯
  --判断是否是庭院
  if pageName == "盯" then
    printLog("判断是否为--盯");
    
    if hasBottomBar() then
      
      --查找庭院文字
      local x, y = findMultiColorInRegionFuzzy(0xacaa95,"91|-4|0x000000,90|11|0x000000,-26|35|0x000000,-18|37|0x000000", 95, 1704, 500, 1948, 560)
      if x > -1 then
        printLog("该界面是盯");
        return true;
      end
      
    end
    return false;
  end
  
  --判断是否是 探索页面
  if pageName == "探索页面" then
    printLog("判断是否为--探索页面");
    local lines = {};
    --结界突破  f8f3e0-333333
    lines[1] = "00201C0783E0F87E1F03C000000000803006004000000000000000100200C0183FFFFFFFFF80F00601C0380701E01C03800000000000000000000000000000000000000781FF3FF7FEF1DE0380701C1BC7FDFFFFFFF9F71CC118020040080303F9FFFFFF9FC0$结界突破$3.11.2060$106";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic,657,1087,782,1216, {"0xf8f3e0-0x333333"}, 95,0,0);
    printLog("识别出来的文字是："..results);
    
    if results == "结界突破" then
      return true;
    end
    
    return false;
  end
  
  --是否是结界突破页面
  if pageName == "结界突破" then
    printLog("判断是否为--结界突破");
    local x, y = findMultiColorInRegionFuzzy(0xf8f3e0,"-12|-6|0xf8f3e0,-8|11|0xf8f3e0,6|9|0xf8f3e0,13|-4|0xf8f3e0,18|20|0xf8f3e0,0|15|0x22180f,22|1|0x695446,-43|3|0xf8f3e0", 95, 979, 67, 1100, 111)

    if x > -1 then
      printLog("判断结果：是突破页面");
      return true;
    end
    printLog("判断结果：不是突破页面");
    return false;
  end
  
  if pageName == "式神碎片" then
    printLog("判断是否为--式神碎片");
    
    local x, y = findMultiColorInRegionFuzzy(0xf8f3e0,"1|-47|0x392a1e,-2|-14|0xf8f3e0,0|-7|0x22180f,-14|1|0xf8f3e0,-1|21|0xf8f3e0,16|7|0x755f50,-9|-11|0xf8f3e0", 95, 1138, 197, 1204, 288)
    if x > -1 then
      printLog("是 式神碎片页面");
      return true;
    end
    return false;
  end
  
  
  if pageName == "准备页面" then
    printLog("判断是否为--准备页面");
    local x, y = findMultiColorInRegionFuzzy(0x22180f,"5|-1|0x22180f,-1|-29|0x241a11,10|4|0xfbfbfb,-11|10|0x22180f,0|10|0x22180f,13|11|0x22180f,21|2|0x312434", 95, 825, 1151, 884, 1215)
    
    if x > -1 then
      printLog("是 准备页面");
      return true;
    end
    
    return false;
  end
  
  --判断是否是战斗页面 （根据识别自动/手动 图标判断）
  if pageName == "战斗页面" then
    printLog("判断是否为--战斗页面");
    
    local lines = {};
    --手动  f4eedc-444444
    lines[1] = "020040080180200C0180700F01E03F8FF1CE700E03C0F01E03C0300200000000000000000000000000000000000000000000000000000000000000000000000000000000000000100200C0180300E01C0380600C0380600C0080100000000000000000000000FFBFF3FE7E0800$手动$9.9.828$47";
    --自动	f4eedc-444444
    lines[2] = "00603C1E0F8FE1F81C03804000000080100600C01801002000000000000000000000000000000000000000000000000000000000000000000000000000000080100600C0180700E01C0300601C0300600400800000000000000000000007FFFFDFFBF0400$自动$6.9.859$45";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic,50,1091,167,1200, {"0xf4eedc-0x444444"}, 95,0,0);
    
    if results == "自动"  or results == "手动" then
      printLog("是 战斗页面");
      
      return true;
    end   
    
    return false;
  end
  
  
  --判断是否是妖怪发现副本中
  if pageName == "妖怪发现副本" then
    printLog("判断是否为--妖怪发现副本")
    
    local lines = {};
    --锁定出战式神  fcfdfd-999999
    lines[1] = "00200C0F8FF3FE7FCF08C1002004008010000080380700E00C001807FEFFDFF9FF0000040180F03C1F83E0380300000000000000000000000000000000000040180700E00C0180300E01C03B0770EF19F33EE3FC1F80F01C0380700E01C07E0FC1F81F03E0380300000000000000000000000000000000000000000000000000000000000000000000000000000200FC1FFFFFFFF7FE000000000000000000000200C0080100200000000000000000000000000000000000000000000000000001FE3FC3F87F0000000000000000000000000E03FC3FF7FE7FC00000000180380780F00F01F00000000000000000000000000000000000000000000000000000000000000000000000000000200FE1FF3FFBFF01E00400801002004C09C13C07C0F80F0000000000000000000000000000000000000000000000000000000000000000180380780F01F01F0180$锁定出战式神$8.0.2944$43";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic,1777,1092,2071,1148, {"0xfcfdfd-0x999999"}, 85,0,0);
    printLog("识别出来的文字是："..results);
    
    if results == "锁定出战式神" then
      return true;
    end  
    
    return false;
  end
  
  
  --判断是否是妖怪发现副本中
  if pageName == "御魂" then
    printLog("判断是否为--御魂副本")
    
    local lines = {};
    --今日掉落  0xf7f2df-0x333333
    lines[1] = "00201C3F0F0FC1E000000000000001801002000000000000000000000000000000000000000000000000000000000000000000000000000000000000700E01C020040080100200400000008010020040080100300700F80F01E000000000000000000000000000000000000000000000000000000000000000000000FF9FC200000000000000000000000000000000001FFFFF8C308210020000200604008010000000000000000000000000000000000000000000000000000000000040881B83FC0E008010020040080100200400C07C3F1F83E004008010020040080100200$今日掉落$10.4.867$40";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic,427,725,646,794, {"0xf7f2df-0x333333"}, 95,0,0);
    printLog("识别出来的文字是："..results);
    
    if results == "今日掉落" then
      return true;
    end  
    
    return false;
  end
  
  
  if pageName == "觉醒" then
    
    printLog("判断是否为--觉醒副本")
    
    local lines = {};
    --掉落奖励  0xf3eddb-0x333333
    lines[1] = "3E07FCFE000000000000000000000000000000000000FFFF9C6184108010000181202004008000000000000000000000000000000000000000000000000000000000020440FC1FE07004008010020040080100200E03E3F8FC1B802004008010020040080100000000000000000000000000000000000000000000000000000000002004000000000003FE00000000000004008070181E0783C42080000000000E03C03004000000000000000000000000000000000000000000000000000F81F03004008010020040080100200400000008000000000000000000000000007F878080$掉落奖励$8.7.1094$41";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic,427,725,646,794, {"0xf3eddb-0x333333"}, 95,0,0);
    printLog("识别出来的文字是："..results);
    
    if results == "掉落奖励" then
      return true;
    end
    
    return false;
  end
  
  if pageName == "组队" then
    printLog("判断是否为--组队界面")
    
    local lines = {};
    --创建队伍  0x282520-0x444444
    lines[1] = "00200C0F87F0FE1FC3803000000000000000000000000000000000000000000000000000FF9FF1FE3FC3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010020040080300700FFFFFFFFEFFC0700C01C0380780700600C008000000000000000000000000000000000000000000000000E01C0380700C0100600C03807C0F80F01E01800000000000000000000000001F03E07C0780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180F0FE1FC1E0300000000000000000000000000000000010020040180300600C0180700E01C03803$创建队伍$13.8.2276$49";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic,1636,1022,1964,1142, {"0x282520-0x444444"}, 95,0,0);
    printLog("识别出来的文字是："..results);
    
    if results == "创建队伍" then
      return true;
    end
    
    return false;
  end
  
  
  if pageName == "组队确认" then
    printLog("判断是否为--组队确认界面")
    
    local lines = {};
    --创建队伍  0x282520-0x444444
    lines[1] = "00200C0787F0FE1F83800000000000000000000000000000000000000000000000000000FF9FF1FE3FC2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020040080300600FFFFFFFFEE380600C0180380380700600C008$创建$13.8.1074$48";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic,1451,991,1576,1047, {"0x282520-0x444444"}, 95,0,0);
    printLog("识别出来的文字是："..results);
    
    if results == "创建" then
      return true;
    end
    
    return false;
  end
  
  
  --是否是邀请组队界面
  if pageName == "协战队伍" then
    printLog("判断是否为--协战队伍界面")
    
    local lines = {};
    --离开队伍  0x282520-0x444444
    lines[1] = "0020040180300600C0180300601C03A06E0DE19E33FE7FC03C0780F01E0380601C0380700E01C0380F01E01C01000000000000000000000000000000000000000000000000000000000000000000401C0380700E01C0380F01E03C0700E03C0780E01E07E0FC1F83F07A1F03C0780F00E018000000000000000000000000000000000000000000000000000000000F01E03C0780E0180300E03C07E0FC0F81F01C02000000000000000000000001F83F07E07C04000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C078FF1FE3F03C02000000000000000000008010020040080300600C0180700E01C0780F01C03803002$离开队伍$2.8.2253$49";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    local results = ocrText(dic, 293,1007,515,1062, {"0x282520-0x444444"}, 95,0,0);
    printLog("识别出来的文字是："..results);
    
    if results == "离开队伍" then
      return true;
    end
    
    return false;
  end
  
  if pageName == "更换式神" then
    printLog("判断是否为--更换式神界面")
		

    
    --首先判断右下角的准备按钮的几个颜色点是否存在
		local x, y = findMultiColorInRegionFuzzy(0xc82a13,"2|38|0xdbaf73,17|-12|0x891408,7|35|0xdbaf73", 95, 2098, 1051, 2173, 1157)
		if x > -1 then
			printLog("找到准备按钮, 继续查找其他标志");
		else
			return false;
		end
		
		
		if isPage("准备页面") then
			--防止把业原火的背景识别成按钮
			return false;
		end
		
		x, y = findMultiColorInRegionFuzzy(0x2d2d9e,"-29|-48|0xffffff,-31|-32|0xffffff,-23|-33|0xffffff,-21|-16|0x22180f,-20|-11|0xffffff,24|-38|0x22180f,29|-25|0xffffff,24|-13|0x22180f", 95, 50, 886, 176, 1009)
    if x > -1 then
      printLog("找到 全部 按钮");
      return true;
    end
    
    x, y = findMultiColorInRegionFuzzy(0x543e2a,"-33|30|0x503a28,52|44|0x4d3826,69|30|0x503a28,17|-13|0x563f2b,3|89|0x473322,33|86|0x473422", 95, 37, 883, 184, 1019)
    if x > -1 then
      printLog("找到 N R SR SSR 按钮");
      return true;
    end
    
    return false;
  end
  
  if pageName == "斗技" then
    printLog("判断是否为--斗技界面")
    
    local x, y = findMultiColorInRegionFuzzy(0xe9d3ac,"86|-82|0xe2cbb0,-47|-87|0x272420,-24|-67|0x272420,-70|-13|0x272420,-57|23|0x272420,-25|19|0x272420,2|-94|0x272420,-76|109|0x932417", 95, 1798, 911, 2043, 1198)
    if x > -1 then
      printLog("找到 战 字， 是斗技页面");
      return true;
    end
    
    return false;
  end
  
  return false;
end

--每次任务之前，先判断是否有弹出框，并做处理，以免程序无法正常运行
function isAlert (alertName)
  
  --判断是否收到协作任务弹出框
  
  --判断是否是邀请弹出框
  
  --判断是否是取消/确认 弹出框
  
  return false;
end


function isTeam () 
  
  local points = {
    {x = 28-86, y = 273 - 215, color = 0x3d2a27},
    {x = 87 - 86, y = 328 - 215, color = 0x4a3c1e},
    {x = 142 - 86, y = 270 - 215, color = 0x412d2b}
  };
  
  local x, y = findMultiColorInRegionFuzzy2(0x62441f, points, 95, 9,187,154,538);
  
  if x ~= -1 and y ~= -1 then
    return true;
  else                 
    return false;
  end
end


function isReceivedInvitation ()
  
  local lines = {};
  lines[1] = "00600C0780F07E0FC7F8FF7FEFFEFFFFF7FE7FC7F87F07E07C07807006004$√$59.6.2411$65";
  local dict = createOcrDict(lines);
  local results = ocrText(dict, 172,376,314,507, {"0x5cb766-0x333333"}, 99, 0, 0);
  
  printLog("识别出来的文字是："..results);
  
  if results == "√" then
    return true;
  else 
    return false;	
  end
  
end

--是否是点击屏幕继续页面
function isTapToContinue () 
  
  --奖励信息
  local x1, y1 = findMultiColorInRegionFuzzy(0x3287cd,"10|-23|0x2e85cc,31|13|0xbc4a20,-30|12|0xb93823,23|47|0x171615", 95, 854,691,1343,1084);
  if x1 > -1 then
    printLog("奖励信息页面");
    return true;
  end
  
  return false;
end

--判断是否是失败鼓
function isFailure ()
  local lines = {};
  local results = "";
  local dict = {};
  
  --失败鼓   0x4d4555-0x222222
  lines = {};
  lines[1] = "0020040180700E01C0780F03E07C0F81F07E0FC3F87F0FE1FC3F87F1FE3FC7F8FF3FE7FCFF9FF3FE7FCFFBFF7FEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFFBFF7FEFFCFF9FF3FE7FCFF8FF1FE1FC3F87F07E0FC0F81F01E03C0380700600400800000000000000000000000000000000000601E03C03C07C0F80F81F03F07E07E0FE1FC1FC3F87F0FE0FC1F81F03E03C0780700E01C01801002$失败鼓$49.47.9947$89";
  dict = createOcrDict(lines);
  results = ocrText(dict, 675,90,958,427, {"0x4d4555-0x222222"}, 95, 0, 0);
  printLog("识别出来的文字是："..results);
  if results == "失败鼓" then
    return true;
  end
  
  return false;
end

--判断是否是胜利鼓
function isVictory ()
  
  local lines = {};
  local results = "";
  local dict = {};
  
  --胜利鼓  0x831b11-0x222222
  lines = {};
  lines[1] = "0020040080300E01C0380701E03C0F81F03E0FC1F87F0FE1FC3F87F0FE1FC7F8FF1FE7FCFF9FF3FE7FCFF9FF3FEFFDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFDFFBFF3FE7FCFF9FF3FE7FC7F8FF0FE1FC3F87F07E07C0F81F03E01C038070060040080000000000000000000000000000000000000000180300300700E01E03C03C0780F80F81F03F07F0FE0FC0F81F03E03C0780700E00C00801002$胜利鼓$48.47.13469$112";
  dict = createOcrDict(lines);
  results = ocrText(dict, 693,100,975,449, {"0x831b11-0x222222"}, 95, 0, 0);
  printLog("识别出来的文字是："..results);
  
  if results == "胜利鼓" then
    return true;
  end
  
  return false;
end


--判断是否是  等待开奖页面   (识别率低，尽量不执行，所以放后最后面)
function isWaitOpenReward ()
  
  --等待开奖页面 
  keepScreen(true);
  local x11, y11 = findMultiColorInRegionFuzzy(0xb83a23,"-5|8|0xb93b22,153|4|0xbb461a,163|18|0xbb381a,18|-86|0xa77a28,148|-80|0xa87a28,55|-206|0xc9592c,104|-207|0xc44f28,92|-95|0xe7e1ce", 95, 878, 396, 1302, 857);
  local x22, y22 = findMultiColorInRegionFuzzy(0xffad76,"6|10|0xffad77,148|-9|0xff9a65,154|2|0xff9060,-2|-89|0xffe682,113|-99|0xffdf7d,70|-220|0xe67043,12|-211|0xef7b4b", 95, 878, 396, 1302, 857);
  local x33, y33 = findMultiColorInRegionFuzzy(0xff9e67,"15|2|0xffa46b,130|9|0xff975e,143|25|0xff8256,8|-91|0xffd372,128|-78|0xfdcc6d,46|-208|0xeb7947,107|-202|0xe36d41", 95, 878, 396, 1302, 857);
  local x44, y44 = findMultiColorInRegionFuzzy(0xa77a28,"114|-1|0xa77a28,130|-32|0x000000,-8|-39|0x000000,-36|98|0xb83823,157|90|0xba401b,73|168|0x000000,61|52|0x9b2212", 95, 878, 396, 1302, 857);
  keepScreen(false);
  
  if x11 + x22 + x33 + x44 > -4 then
    printLog("等待开奖页面");
    return true;
  end
  
  return false;
end

--是否是获得奖励页面
function isGetReward () 
  
  local lines = {};
  --获得奖励  0xf3e6af-0x555555
  lines[1] = "00603C0783F07E0FC1F83F03E03C0780F01E01C0180300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080307E1FC7F9FF3FEFFDFFFFF7FE7FCFF8FF0FE0FC0F800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100600C0380700E01C0180300000000000000000000000000000000000000000000000000000000000000380F03E0FC1F83F07E0FC0F80F01E03C0780F01E03C0780F01E03C0780F01E03C0F81F07E0FC1F83F07E0FC1F83F07E0FC1F83F07E0FC1F83F07E0FC1F81F01E03C01803$获得奖励$23.255.12158$113";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,792,310,1419,478, {"0xf3e6af-0x555555"}, 90,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "获得奖励" then
    return true;
  end  
  
  return false;
end

function isCooperation ()
  local isCooperation = false;	--是否为协作任务
  local isValueType = false; --是否为奖励勾玉或体力任务
  
  
  local lines = {};
  --悬赏封印邀请  0x272420-0x333333
  lines[1] = "01E0FC3F87F07A0E01C0300601C0380600C0180700E01FE3FCFF9FF1FE1FC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F01FA1FC1F8070060040080300600DFFFFF7FEFFC6380300E01C0781F07E1DC799F37E67CC6180300600C0180300600C0380700E00C00800000000000000000000000000000000000000000000000000000003F0FE3FC7F87F07E00000000000000000000000000000000000000000000000000000603FC7F8FF1FE1FC0F8000000000000000000000000000000000000000000000000E03C0780F01E03C0780F01E07C0F83F07E0FC1F80E01C00000000000000000000000000000000000000000000000000000000000080300601C018030060040000000000000000000000000000000000000000000000000000000000000000000380701E03C1F87F7FE7DC$悬赏封印邀请$14.250.4693$61";
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,855,223,1335,340, {"0x272420-0x333333"}, 90,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "悬赏封印邀请" then
    isCooperation = true;
    
    ----是否为奖励勾玉或体力任务
    --勾玉
    local x1, y1 = findMultiColorInRegionFuzzy(0xe8513b,"23|5|0xba130f,34|32|0xb51412,11|74|0xc2150d,5|49|0xa0846f,-15|79|0x8e7460,-14|48|0xd2b497,-27|20|0xc5ac8e", 95, 1115, 785, 1244, 908);
    if x1 > -1 then
      isValueType = true;
    end
    
    --体力
    local x2, y2 = findMultiColorInRegionFuzzy(0xffb451,"22|-2|0xee3326,7|43|0x0d0f0b,44|16|0xd83021", 95, 1120, 787, 1239, 904);
    if x2 > -1 then
      isValueType = true;
    end
    
  end 
  
  return isCooperation, isValueType;
end

--判断是否是探索或挑战弹出框
function isExplorationAlert ()
  local lines = {};
  --探索  0xfcfaf8-0x666666
  lines[1] = "201FF3FFBFF7FE780000000000000080301E07C1E0380700C0188300600C0380700C0180300E01C0300601C03DC7F0FE0FC0F00E0180$探索$7.5.1290$109";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,1860,402,1944,566, {"0xfcfaf8-0x666666"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "探索" then
    return true;
  end  
  
  return false;
end

--判断是否是组队邀请
function isMakeTeamAlert ()
  local lines = {};
  --组队获得  0x272420-0x444444
  lines[1] = "00201C1F87F07C0F000000000000000000000040180300600C0180300600C0180700E01C0380300600C0000000000000000000000000000000000600F01E03C0780C0380F01F83F07E07806000000000000000000000F83F07E0FC0400000000000000000000000000000000000000000000000000000000000000000180300600C0180700E01C7F8FF1FE1FC0780E0180300600C01803C0F87F7FFFFBFE3FC6780F01E03C0780F01E03C0300000000000000000000000000000000000000080300E03C3F8FE3F07C070040000000200F01FE3FC7F8EF19C338661CC398E31C638D71EFFDFF9FF1F83C0200$组队获得$6.4.2262$43";
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,1028,189,1586,247, {"0x272420-0x444444"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "组队获得" then
    return true;
  end  
  
  return false;
  
end


--判断是否是继续邀请战斗
function isContinueMakeTeam ()
  local lines = {};
  --邀请队友继续  0x302c27-0x555555
  lines[1] = "0300700F00F01C0080000000601C0380F07E3F5FEBFC1B80740F80F01E0180000000203C7F8FF1E01800000000000000000000000000000000000000000000000000000080380780780F81F000000000000000100300601C039FF7FFFFF7FE1E43C8730E21C4180200000000000000000000000000000000000000000400F03E07C0781C0380F01E83F07E0FC0E00C000000000000000000003F07E0FC1F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E3FCFF9FF1F23840080100600C0180300601C03803006000000000000000000000000000000000000000000000000000300E1FC7F8FC0F00C0000000000300780F00E00C00000000004000000003FC7F8FF0000000080301E03C030000000000000000000000000000000000000000000080707E3FC7E0F80E0000008$邀请队友继续$4.3.3209$43";
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,795,501,1416,581, {"0x302c27-0x555555"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "邀请队友继续" then
    return true;
  end  
  
  return false;
end

--是否是攻破记录进度重置
function isResetRecord ()
  local lines = {};
  --进度将重置  0x302c27-0x555555
  lines[1] = "0300700F01F03E03C00000000000000000000C03F87F0FE0FC00000002FC5FFBFF7FE01C0180300600000000000000000000000000000000000000000000000000000000000780700E01C0380700E01C0780F61EE39EE3FC7F87F01E03F07E0FC1E87C0F00E01800000000000000000000000000000000000000000000000000000000003E07FCFF8FF1E00000000100601C0380F03E1F4FE3F87F0FF01E03907E0FC1F83F07C0700400000000000000000000000000000000000000000000000000000000200700E01C0780F01F43F8FF1FE7FCFFBE1783F05E088300600C0180300600C0380700E01C018030000000000000000000000000000000000001E03F87F0FE1C4308611E23F47F8DF18E304608C31FE7FCFF9E3386E0DC3BC77FE7FCFF0FC1E0080$进度将重置$4.5.3115$42";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,718,464,1488,607, {"0x302c27-0x555555"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "进度将重置" then
    return true;
  end  
  
  return false;
end



--是否是组队页面
function isMakeTeamPage ()
  local lines = {};
  --离开队伍
  lines[1] = "00200C0180300600C0180700E01C03E07E0FE1FE73FE7FC67C0780F03E07C0F01E0380700E03C0780F01E03C03800000000000000000000000000000000000000000000000000000000000000200401C0380700E01C0780F01E03C0F81E03C0780F03F07E0FC1F83F0FA1F03C0780F01E01C000000000000000000000000000000000000000000000000000000000F01E03C0780F01C0700E03C07E0FC0F81F03C03000000000000000000000001F83F07E0FC0E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001C078FF1FE3F03C02000000000000000004008010020040180300601C0380700E01C0780F01E03C07006$离开队伍$2.8.2553$49";
  
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic, 351,965,693,1110, {"0x272420-0x666666"}, 95,0,0);
  
  if results == "离开队伍" then
    return true;
  end
  
  return false;
end


--判断是否是队长 根据是否有开始战斗按钮
function isTeamLeader ()
  printLog("判断是否是队长");
  
  local lines = {};
  --开始战斗
  --可点击
  lines[1] = "0080100700E01E03C0781F03E07C0F01C0780F01E03C0FC1FC3F87F0FE3EC780F01E03C038040000000000000000000000000000000000000000000000000000000000000000000000000000033FE7FCFF9FE1E00000000000000000000000000000000000000000307E7FCFF8FF1F81E0300000000000000000000000000000000000000000000000000000000000000000000401FE3FC3F87F000000000000000000000000000000780FE1FFFFFBFF00E000000000001C03C0380780F80E000000000000000000000000000000000000000000000000000000000000000000000000000000000000100700F01E01C0380300000000600FFFFFFFFFFF7E0$开始战斗$9.17.2275$48";
  --不可点击
  lines[2] = "00401C0380700E01C0780F03E07C0F81F03E07C0F83F07E0FC3F87F0FE1FC3F87C1F83F07E07C0F0000000000000000000000000000000000000000000000000000000000000000000000000001FE7FCFF9FF3FE3F83800000000000000000000000000000000000100E3FCFF9FF1FE1FC3E07C0400000000000000000000000000000000000000000000000000000000000000000FE1FC3F87F0FE0C00000000000000000000000003007F0FFDFFBFF7FEFFC000000400E01E03C07C0FC0F81F01C000000000000000000000000000000000000000000000000000000000000000000000000000000180780700E01C0380700600000200FFFFFFFFFFF7FEFFCF80$开始战斗$9.17.3170$50";
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic, 1684,1007,1916,1069, {"0x272420-0x666666"}, 95,0,0);
  
  if results == "开始战斗" then
    printLog("判断结果是：是队长");
    return true;
  end
  return false;
end

--组队是否可以开始战斗
function isCanBeginFight ()
  printLog("判断是否可以开始战斗");
  local x, y = findMultiColorInRegionFuzzy(0xf3b25e,"-113|29|0xf3b25e,4|60|0xf3b25e,124|27|0xf3b25e", 95, 1514, 968, 1851, 1103);
  
  if x > -1 then
    printLog("判断结果是：可以开始战斗");
    return true;
  end
  return false;
end


--判断是否是觉醒页面
function isGetAwake ()
  
  local lines = {};
  --火麒麟  0xf8f3e0-0x444444
  lines[1] = "0020040080000000000000000000001FFFFFFFDFF870000000000000000000000100601C03807002$火麒麟$8.10.1128$105";
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,213,647,288,850, {"0xf8f3e0-0x444444"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "火麒麟" then
    return true;
  end  
  
  return false;
end

--判断是否是登录页面 
function isLoginAlert ()
  local lines = {};
  --登录  0xffffff-0x444444
  lines[1] = "00601DF7BE77CEF8DF0BE07C0F81F03E07C6F9DFFBFF7FEFFDFE3F0000000C03E0FF1FF0FF0FF07E0FC3F8FF3FAFE1F81E01800040080701E03C03803000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F01E03C2784F09E13C2784F09E13C2784F09E13C2784F09E13C2784F09E13C2784F09E13C27FCFF9FF3FE7FC$登录$3.9.2171$50";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic, 1122,547,1367,639 , {"0xffffff-0x444444"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "登录" then
    return true;
  end  
  return false;
end


--断线弹出框
function isOffLine() 
  local lines = {};
  --断线  0x302c27-0x555555
  lines[1] = "01E03C0780F00E00C0080300600400FFFFFEFFDFF80000001C0F81F01C0300300700E01C0180300E03C0701E07C1F07E0F81F01E018010000000000000000000000000000000000000000000000000000000703E3FCFF8FE0F01C00000000000000000801E03F07FFFFFFFCFF80000000000000000704E09E13E23E078070$断线$1.8.1555$48";
  --断开连接 
  lines[2] = "07E0FC0F81C00000007006001FFFFFFFF0000180F0380F00C00000803E07C0F8180300E0380701C0780F01C0$断$1.4.499$40";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic, 879,484,996,550 , {"0x302c27-0x555555"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "断线" then
    return true;
  end  
  
  return isOffServer();
  
end


--断开服务器
function isOffServer ()
  local lines = {};
  --断开服务器  0x443e36-0x333333
  lines[1] = "07E0FC0F81C00000007006001FFFFFFFF0000180F0380F00C00000803E07C0F8180300E0380701C0780F01C0$断$1.4.499$40";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic, 801,537,846,586 , {"0x443e36-0x333333"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "断" then
    return true;
  end  
  return false;
end

function isPowerAlert() 
  local lines = {};
  --足  0x302c27-0x555555
  --ios9的弹出框
  lines[1] = "07E0FC1F83F07E0F81F03E07C0F81F03E07C0FC1F83F07E0FC00000000000000000003FCFF9FF3FE7FC000000000000000000000000000FFFFFFFFFFF7F0$足$0.0.889$45";
  --ios8的弹出框
  lines[2] = "01007C0F81F03E07C0F81F03E07C0F81F03E07C0F81F03E02000000000000000000E01FC3F87F0FE0000000000000000000001FC1FFBFF7FEFFC3E0$足$0.0.733$45";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  
  local results = ocrText(dic, 965,460,1041,520 , {"0x302c27-0x555555"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "足" then
    return true;
  end  
  return false;
  
end



--购买体力弹出框
function isBuyEnergyAlert() 
	--判断是否是购买体力弹出框
	local isAlert = false;
	local x, y = findMultiColorInRegionFuzzy(0xf3b25e,"113|-35|0xd2cbc3,-284|-40|0xd2cbc3,63|-174|0x22180f,2|-176|0x22180f,53|-176|0xd6c9b9,15|-181|0xd6c9b9,440|-492|0xe8d4cf,-280|-432|0x655448", 95, 861, 308, 1650, 860)
	if x > -1 then
		isAlert = true;
	
	else
		return false, "";
	
	end


	local lines = {};
  --80  0x22180f-0x333333
  lines[1] = "03E3FC7FBFF700C0100600C01801C0BE37FEFFDFF8FF01C000000000000000180F07E1FCFFBF87E1F83E03C0700700600E01C03C03F81F01E$80$2.1.574$33";
  --60
  lines[2] = "00607C1F8FF3E0701C0700E0180380700F81FC1FC1FC0F0000000000000000080703E0FC7F9FC3F0FC1F01E0380380300700E01E01F80F00E$60$1.1.539$34";
	
  --加载自定义字库
  local dic = createOcrDict(lines);
  
  local results = ocrText(dic, 1117,805,1166,851 , {"0x22180f-0x333333"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  
	
	
  return isAlert, results;
end

--游戏公告
function isAnnouncementAlert ()
  
  local x, y = findMultiColorInRegionFuzzy(0xd1c8c1,"39|-1|0x807064,48|-1|0x807064,48|-6|0xd1c7c0,-42|-1|0x655448,-44|-1|0x655448", 95, 1265, 91, 1461, 198)
  if x > -1 then
    return true;
  end
  
  return false;
end



--判断是否是进入游戏页面
function isIntoGamePage ()
  local lines = {};
  --进入游戏  0xffffff-0x333333
  lines[1] = "700E03C07C0780F01F03E17FE7FCFF8FF1FE1FC1F81F03E01C03803002$进入游戏$9.22.369$30";
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,1041,1058,1107,1106, {"0xffffff-0x333333"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "进入游戏" and isLoginAlert() == false then
    return true;
  end
  
  return false;
  
end


--点击屏幕进入游戏
function isTapToIntoGame ()
  
  local lines = {}
  lines[1] = "0700E03E07C0F81F07E0FC3F07C0F83E1FCFFFFFFFFFFFFFFFFFBFF71E07C18020$神乐$0.0.291$25";
  --加载自定义字库
  local dic = createOcrDict(lines);
  local results = ocrText(dic,1175,630,1211,668, {"0xffffff-0x333333"}, 95,0,0);
  printLog("识别出来的文字是："..results);
  
  if results == "神乐" then
    return true;
  end
  
  return false;
  
end


---活动页面
function isActivityPage ()
  
  --识别关闭文字
  local x, y = findMultiColorInRegionFuzzy(0x000000,"-7|-7|0x000000,7|-6|0x000000,-14|0|0x000000,14|0|0x000000,-1|12|0x000000,-15|27|0x000000,15|27|0x000000,0|-7|0xffffff, 5|5|0xffffff,5|15|0xffffff,-7|16|0xffffff,0|22|0xffffff", 99, 2021, 21, 2158, 98)
  if x > -1 then
    return true;
  end
  
  return false;
end

--提示的活动页面
function isNoticeActivityPage()
  local x, y = findMultiColorInRegionFuzzy(0xe8d4cf,"0|-73|0x332620,-27|-75|0x593921,-5|157|0x8d7245,-3|180|0x8d7245", 95, 1761, 205, 1891, 508)
  if x > -1 then
    return true;
  end
  return false;
  
end


----在探索页面判断是否有突破券
function isHasBreakTicket ()
  printLog("在 探索页面 判断是否有突破券");
  local lines = {};
  --返回 0xffffff-0x666666
  lines[1] = "00E07C3F9C030080300600C0180300600400600F007F07E00C$0$0.0.159$29";
  lines[2] = "0201E0FC1C0701C0300600C01803007007007FC7F87F$2$0.1.153$29";
  lines[3] = "00E00038000E00$/$8.0.21$27";
  lines[4] = "0E01C0601C07E1FFFFFBFF$1$0.0.105$29";
  lines[5] = "080380F01C0701C0300600C0180700F0779E7F87E0$3$0.2.158$29"
  
  local dict = createOcrDict(lines);
  local result = ocrText(dict, 1351,20,1509,80, {"0xffffff-0x666666"},98, 0, 0);
  printLog("识别出来的文字是："..result);
  if result ~= "0/30" then
    return true;
  end
  
  return false;
end


--在探索页面判断是否有体力
function isHasTiLi (number)
  printLog("在 探索页面 判断是否有足够的体力");
  local lines = {};
  --返回 0xffffff-0x666666    需要 0 - 9 所有的数字
  lines[1] = "00E07C3F9C030080300600C0180300600400600F007F07E00C$0$0.0.159$29";
  lines[2] = "0201E0FC1C0701C0300600C01803007007007FC7F87F$2$0.1.153$29";
  lines[3] = "00E00038000E00$/$8.0.21$27";
  
  local dict = createOcrDict(lines);
  local result = ocrText(dict, 1351,20,1509,80, {"0xffffff-0x666666"},98, 0, 0);
  printLog("识别出来的文字是："..result);
  
  --获取“/”前面的数字
  local i, j = string.find(result, "/");
  local resultNumber = string.sub(s,1,i);
  
  printLog("剩余的体力为："..resultNumber);
  
  if tonumber(resultNumber) > number then
    return true;
  end
  
  return false;
end


----在突破页面判断是否有突破券
function isHasBreakTicketInBreakPage ()
  printLog("在 突破页面 判断是否有突破券");
  local lines = {};
  --返回 0x34302b-0x444444
  lines[1] = "00E07C3F8FF3C0F0180700E0180380700F00F00F80FF0FE07C018$0$0.0.229$30";
  lines[2] = "0301F07F1F87C0F03C0700E01C0380780700FFCFF8FF07E$2$0.1.215$30";
  lines[3] = "00E03C3E0F8F81E02000$/$8.0.69$29";
  lines[4] = "0701E0781E07FFFFFFFBFF$1$0.0.125$30";
  lines[5] = "0C03C0FC1F0780E0380700E01C0780F877FEFFCFF838$3$1.2.228$30";
  
  local dict = createOcrDict(lines);
  local result = ocrText(dict, 651,1022,844,1108, {"0x34302b-0x444444"},98, 0, 0);
  printLog("识别出来的文字是："..result);
  
  if result ~= "0/30" then
    return true;
  end
  
  return false;
end


--判断是否是结界突破的弹出框
function isBreakAlert() 
  local x, y = findMultiColorInRegionFuzzy(0x605755,"21|-13|0x605755,-1|11|0x605755,1|-50|0x231113,5|42|0x2a1317", 95, 1966, 44, 2112, 186)
  if x > -1 then
    return true;
  end
  
  return false;
end

--判断组队页面是否有需要加入的队伍
--teamArray:需要加入的队伍数组

function hasTapJoinInTeam (teamArray) 
	printLog("需要打的妖怪数组是："..#teamArray);
  printTable(teamArray);
	
  --所有妖怪
  if #teamArray == 0 then
		local x, y = findMultiColorInRegionFuzzy(0xdfcdb3,"49|0|0xdfcdb3,93|2|0xdfcdb3,-2|0|0xdfcdb3", 95, 1721, 309, 1937, 444)
		if x > -1 then
      tap(1833,359);
			mSleep(300);
      return true;
    else
      return false;
    end
  end
  
  
  local lines = {};
  
  --石距 0x272420-0x666666
  --lines[1] = "0600C0180700E01C0380701E03FC7F8FF1FE7F0F01C0380F01E03C0780F01E0780700E01C00000000000000000000000000000000000000003807E0FF1FE204408C0102204E1BFF3FE3FC700000000007E1FF1FE3FC600C0180300E0180300E01C0380700C0180300$石距$9.3.899$36";
  --年兽
  --lines[2] = "00200C0381F0FCFF9FF3CE60C03C0780F01E03C0E01C0380701C0380700E000000000000000000000000000000000000000000000000000000000000000000400801102304708710F20C40080300600C078070EE3DDF3FC7F0CC1D8380300600C008$年兽$9.7.880$43";
  --经验妖怪
  --lines[1] = "00201C0787C3F1FC3F078020201C01803002000000700E01C0380600C0180300C118E73CFF1FC3F03C030040$经验妖怪$3.6.447$35";
  --金币妖怪
  --lines[2] = "00201C0783E0F8FC3F87F03E00E00E00E00E00C01801$金币妖怪$13.14.455$40";
  --鬼使黑
  lines[1] = "00C01C0380700C0180601C1F8FFBF7F8FF1E0640C0180300601C03807207C0F80F00C$鬼使黑$6.10.487$41";
  --跳跳哥哥
  lines[2] = "0380FC1F83B040180300600C01FC3F87F070040000000000003007F0FE0FC00000F01FFFFFBC000000000001006004008$跳跳哥哥$4.3.496$37";
  --骨女
  lines[3] = "3E07FCFF9FF308610C619E23E43C87B00C01C03C07FF7FEFF0E00$骨女$9.10.430$42";
  --海坊主
  lines[4] = "0600E00F01E0000000000000200C0781F1FCFF3FE7FC3180300E01C0300600C0380700E018010$海坊主$6.7.492$42";
  --二口女
  lines[5] = "080180700E01C0380701E03C0780E01C0380701E03C0780E03C0780F01E01C0100$二口女$9.10.234$27";
  
  --饿鬼
  lines[6] = "0021FC7F8FC0E000000000000000000000000000000300600C00E00FC1FFFFF81F0000000000C01C01C$饿鬼$7.6.527$40";
  --椒图
  lines[7] = "FFFFFDF000000000000000000000700FF1FE1FC0180300600C03002$椒图$8.15.472$38";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  
  local point = ocrText(dic, 719,298,1118,974, {"0x272420-0x666666"}, 95,1,0);
  
  if #point ~= 0 then  --如果找到符合条件的点
    for var = 1,#point do
		
			printTable(point);
      for i,v in ipairs(teamArray) do
        if point[var].text == v then
          local x, y = point[var].x, point[var].y;
          printLog("已点击，找到："..v.." 位置是： x = "..x.." y = "..y);
          tap(1850, y + 50);
          mSleep(800);
          return true;
        end
      end
    end
  end
  
  return false;
end


function isChangeSkinAlert()
  printLog("判断是否是庭院换肤弹出框");
  local x, y = findMultiColorInRegionFuzzy(0xede2d0,"49|-3|0xede2d0,-50|-4|0xede2d0,0|47|0xede2d0,-1|-57|0xede2d0,74|-7|0xede2d0,-1|67|0xede2d0,-76|-6|0xede2d0", 95, 1018, 361, 1220, 565);
  
  if x > -1 then
    printLog("是庭院换肤弹出框");
    return true;
  else
    return false;
  end
end

--判断是否找到了满字
function hasFindFullInArea(area)
  local x, y = findFullInArea(area);
  
  printLog("找到了满字：x:"..x..", y:"..y);
  
  if x > -1 then
    return true;
  else
    return false;
  end
end

